<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;


/**
 * Game模型
 */
class PlanNumber extends ModelBase
{

    protected $insert = ['create_time'];




    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }

    /**
     * 连彩种分类表
     */
    public function lottery(){
        return $this->belongsTo('Lottery','lottery_id','id');
    }

    /**
     * 连玩法表
     */
    public function plan(){
        return $this->belongsTo('ThirdPlan','plan_id','id');
    }

    /**
     * 获取状态信息内容
     */
    public function getStateHtmlAttr(){

        switch ($this->state){
            case 1:
                $html='<span class="el-tag el-tag--mini">进行中</span>';
                break;
            case 2:
                $html='<span class="el-tag el-tag--success">中奖</span>';
                break;
            case 3:
                $html='<span class="el-tag el-tag--danger">未中奖</span>';
                break;


        }
        return $html;
    }

    /**
     * 连玩法表
     */
    public function getRewardRateAttr(){
        if($this->state==1 || $this->state==3){
            return 0;
        }
        $list=BetsLogSubscribe::where(['plan_number_id'=>$this->id])->select();
        $ra=100;
        $rate=100/$this->round;
        foreach ($list as $k=>$v){
            if($v->state==3){
                $ra-=$rate;
            }
        }
        return floatval(format_money($ra,2));


    }

    /**
     * 时间自动完成
     */
    public function getCreateTimeAttr($value)
    {

        return date('Y-m-d H:i:s',$value);
    }

}
